var express = require('express');
var router = express.Router();
var mysql = require('mysql');

var config = require('../../config/config.js');
var db = mysql.createPool({ host: config.host, user: config.user, password: config.password, database: config. database})



router.use(function(req, res, next) {
    if (!req.session.user && req.url != '/login') {
        res.redirect('/login');
    } else {
        next();
    }

})


router.get('/', function(req, res, next) {
    console.log(req.session.user)
    res.render('admin/index', {
        userInfo: req.session.user
    })
})

router.get('/get_admin',function(req,res,next){
    res.send('get_admin')
})

router.use('/settings', require('./settings.js'));
router.use('/users', require('./users.js'));
router.use('/tag', require('./tag.js'));
router.use('/menu', require('./menu.js'));
router.use('/article', require('./article.js'));

// 退出
router.get('/logOut', function(req, res, next) {
    delete req.session.user;
    res.redirect('/login');
})


module.exports = router
